package com.hqyj.javaSpringBoot.modules.common.service.impl;

import com.hqyj.javaSpringBoot.modules.common.dao.ExceptionLogDao;
import com.hqyj.javaSpringBoot.modules.common.entiy.ExceptionLog;
import com.hqyj.javaSpringBoot.modules.common.entiy.ResultEntity;
import com.hqyj.javaSpringBoot.modules.common.service.ExceptionLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

@Service
public class ExceptionLogServiceImp implements ExceptionLogService {

    @Autowired
    private ExceptionLogDao exceptionLogDao;

    /**
     * 添加异常信息
     * @param exceptionLog
     * @return
     */
    @Override
    public ResultEntity<ExceptionLog> insertExceptionLog(ExceptionLog exceptionLog) {
        List<ExceptionLog> exceptionLogs =
                Optional.ofNullable(exceptionLogDao.getExceptionLog(exceptionLog)).orElse(Collections.emptyList());
        if (exceptionLogs.isEmpty()){
            exceptionLogDao.insertExceptionLog(exceptionLog);
        }
        return new ResultEntity<ExceptionLog>(
                ResultEntity.ResultStatus.SUCCESS.code,"Insert success",exceptionLog);
    }
}
